﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Kmust.App_Data.KmustDataTableAdapters;
using System.Data;
using Kmust;
using System.Threading;
using System.Windows;


namespace Kmust.Commom
{
    public static  class KmustDate
    {
        private static Thread dataThread;
        public static Kmust.App_Data.KmustData.AuthorizeDeviceDataTable autdev;
        public static Kmust.App_Data.KmustData.ExperimentDeviceDataTable expdev;
        public static Kmust.App_Data.KmustData.XSDataTable xst;
        public static Kmust.App_Data.KmustData.JSDataTable jst;
        public static Kmust.App_Data.KmustData.AuthorTargetDataTable auttar;
        public static Kmust.App_Data.KmustData.OrganizationDataTable orgtab;
        public static Kmust.App_Data.KmustData.RoomDataTable roomtab;

        public static void init()
        {
            dataThread = new Thread(getDate);
            dataThread.Start();
        }


        private static void getDate()
        {
            try
            {
                using (App_Data.KmustDataTableAdapters.AuthorizeDeviceTableAdapter at = new AuthorizeDeviceTableAdapter())
                {
                    autdev = at.GetData();
                }

                using (App_Data.KmustDataTableAdapters.ExperimentDeviceTableAdapter exp = new ExperimentDeviceTableAdapter())
                {
                    expdev = exp.GetData();
                }
                using (App_Data.KmustDataTableAdapters.XSTableAdapter xs = new XSTableAdapter())
                {
                    xst = xs.GetData();
                }
                using (App_Data.KmustDataTableAdapters.JSTableAdapter js = new JSTableAdapter())
                {
                    jst = js.GetData();
                }
                using (App_Data.KmustDataTableAdapters.AuthorTargetTableAdapter aut = new AuthorTargetTableAdapter())
                {
                    auttar = aut.GetData();
                }
                using (App_Data.KmustDataTableAdapters.OrganizationTableAdapter org = new OrganizationTableAdapter())
                {
                    orgtab = org.GetData();
                }
                using (App_Data.KmustDataTableAdapters.RoomTableAdapter room = new RoomTableAdapter())
                {
                    roomtab = room.GetData();
                }
            }catch(Exception e)
            {
                MessageBox.Show("初始化失败，请联系管理员！");
            }
        }

        public static void threadClose()
        {
            dataThread.Abort();
        }
      
    }
       
    
}
